package com.sgzn.sgpay.web.controller;


import com.sgzn.sgpay.model.request.SgsDepositRequest;
import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.service.SgsDepositService;
import com.sgzn.sgpay.web.controller.base.UserBaseController;
import com.sgzn.sgpay.web.handle.AssembleCommonHandle;
import com.sgzn.sgpay.web.request.Impl.DepositRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 充值控制器
 * @author huangsenguang
 */
@Slf4j
@Controller
@RequestMapping("/user")
public class DepositController extends UserBaseController{

    @Resource
    private SgsDepositService sgsDepositService;
    @Resource
    private AssembleCommonHandle assembleCommonHandle;

    @RequestMapping("/deposit")
    @ResponseBody
    public SgsResultResponse<Map<String, String>> deposit(DepositRequest request){
        super.setUserInfo(request);
        return sgsDepositService.deposit(assembleRequest(request));
    }

       /**
     * 组装服务请求
     * @param request
     * @return
     */
    private SgsDepositRequest assembleRequest(DepositRequest request) {
        SgsDepositRequest sgsDepositServiceRequest = new SgsDepositRequest();
        sgsDepositServiceRequest.setAmount(request.getAmount());
        assembleCommonHandle.assembleUserRequest(request, sgsDepositServiceRequest);
        return sgsDepositServiceRequest;
    }

}

